<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title><?php echo ((isset($title) && ($title !== ""))?($title):get_system_config("system_name")); ?></title>
		<link href="/Public/Ins/css/bootstrap.min.css" rel="stylesheet">
		<link href="/Public/Ins/font-awesome/css/font-awesome.css" rel="stylesheet">
		<link href="/Public/Ins/css/animate.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/toastr/toastr.min.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/gritter/jquery.gritter.css" />
		<?php if(!empty($plugin["jquery-ui"])): ?><link rel="stylesheet" href="/Public/Ins/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css" />
	<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><?php endif; ?>

	<link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />


		<link href="/Public/Ins/css/style.css" rel="stylesheet">
		<link href="/Public/Ins/css/xiaowei.css" rel="stylesheet">
		<link href="/Public/Ins/css/nprogress.css" rel="stylesheet">
		<script src="/Public/Ins/js/nprogress.js"></script>
		<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />
		
	</head>
	<script type="text/javascript">
	var upload_url = "<?php echo U('upload');?>";
	var del_url = "<?php echo U('del_file');?>";
	var app_path = "";
	var cookie_prefix = "<?php echo C('COOKIE_PREFIX');?>";
	var link_select = "<?php echo U('Popup/link_select');?>";
	
</script>

	<body class="<?php echo (CONTROLLER_NAME); ?>">
		<div class="shade"></div>
		<div class="form-group hidden" id="img_upload_container">
			<div id="img_upload">上传</div>
		</div>
		<nav class="navbar navbar-default row" role="navigation" id="top_menu">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-6">
					<span class="sr-only">Toggle navigation</span>
					<i class="fa fa-bars fa-lg"></i>
				</button>
				<div class="hidden-xs">
					&nbsp;
				</div>
				<a href="<?php echo U('index/index');?>" class="navbar-brand"><?php echo get_system_config("system_name");?></a>
			</div>
			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse" id="navbar-collapse-6">
				<ul class="nav navbar-nav navbar-right">
					<?php if(is_array($top_menu)): foreach($top_menu as $key=>$top_menu_vo): ?><a class="nav-app" href="#" url="<?php echo (get_nav_url($top_menu_vo['url'])); ?>" node="<?php echo ($top_menu_vo["id"]); ?>" onclick="click_top_menu(this)" ><i class="<?php echo ($top_menu_vo["icon"]); ?>"></i><?php echo ($top_menu_vo["name"]); ?>
						<?php if(!empty($badge_count[$top_menu_vo['id']])){ $html=''; $html='<span class="label label-danger">'.$badge_count[$top_menu_vo['id']].'</span>'; echo $html; } ?></a><?php endforeach; endif; ?>
					<a class="nav-app btn-danger" href="<?php echo U('public/logout');?>"><i class="fa fa-sign-out"></i>退出</a>
				</ul>
			</div><!-- /.navbar-collapse -->
		</nav>
		<div id="wrapper">
			<div class="sidebar navbar-static-side" id="sidebar">
				<div id="user_info" class="text-center hidden-xs"  >
					<span >当前用户：<?php echo (session('user_name')); ?></span>
				</div>
				<div id="nav_head" class="text-center" onclick="toggle_left_menu()">
					<span class="menu-text"><?php echo ($top_menu_name); ?></span>
					<b id="left_menu_icon" class="fa fa-angle-down pull-right"></b>
				</div>
				<?php echo W('Sidebar/left',array('tree'=>$left_menu,'badge_count'=>$badge_count));?>
			</div>
			<div id="page-wrapper" class="gray-bg">
				<div class="row wrapper border-bottom gray-bg">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="fa fa-home home-icon"></i>
								<a href="/">Home</a>
							</li>
							<li>
								<?php echo ($top_menu_name); ?>
							</li>
						</ul><!-- .breadcrumb -->
					</div>
				</div>
				<div class="wrapper wrapper-content">
					
<link href="/sap/demo.css" rel="stylesheet" type="text/css" />
<script src="/sap/scripts/boot.js" type="text/javascript"></script>
<style>
.mini-grid-row{height: 30px}
table img{width: 40px}
</style>


<body style="">
<div class='show-pic'><img /></div>
			<input type="input" class='mini-textbox' id='pid'style="width: 180px;display: none" value="<?php echo ($id); ?>" /> <span class='span'>
			 
		      &nbsp;&nbsp;选择清单:<input id="combo1" onValuechanged="change()" class="mini-combobox" style="width: 320px;" textField="name" valueField="id" emptyText="请选择清单..." url="/Shelves/getMylist" value="" allowInput="true" showNullItem="true" nullItemText="请选择清单..." />
				<a class="mini-button" iconCls="icon-downgrade" onclick="send()">通知上架</a>
				<br/>
				<br/>
				<div id="grid2" class="mini-datagrid" style="width: 100%; height: 500px;"  allowCellEdit="true" 	idField="id" multiSelect="true" showPager="false" allowCellEdit="true" allowCellSelect="true"
				onCellendedit='cellendedit'
				>
				 <div property="columns">
					    <div header="日期" field="ctime"  ></div>
				        <div header="物料编号" field="code" ></div>
				        <div header="物料名称" field="name" ></div>
				        <div header="颜色" field="color" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>
				        <div header="图片" field="img" ></div>
				        <div header="订货说明" field="caption" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>
				        <div header="毛利" field="maoli" ></div>
				        <div header="商城价" field="mall_price" > <input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="市场价" field="market_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="毛利率" field="maolilv" ></div>
				        <div header="采购价" field="purchase_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="实际采购价" field="r_purchase_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="分期数" field="by_stages" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="费率（%）" field="by_stages_rate" ><input property="editor" class="mini-spinner" minValue="0" maxValue="100" /></div>
				        <div header="预估运费" field="freight" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="赠品价格" field="gift_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="银行佣金" field="bank_commission" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="增值税等17%" field="zzs" ></div>
				        <div header="包装费" field="packing_charge" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="返利金额" field="rebate" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>
				        <div header="天猫" field="tamll" ></div>
				        <div header="天猫销售数量" field="tamll_sale" ></div>
				        <div header="京东" field="jd" ></div>
				        <div header="京东销售数量" field="jd_sale" ></div>
				        <div header="广发" field="guangfa" ></div>
				        <div header="建行" field="jianhang" ></div>
				        <div header="招行" field="zhaohang" ></div>
				        <div header="交行" field="jiaohang" ></div>
				        <div header="民生" field="minsheng" ></div>
				        <div header="平安" field="pingan" ></div>
				        <div header="中信" field="zhongxin" ></div>
				        <div header="产品毛重(kg)" field="weight" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>
				        <div header="外包装尺寸" field="packing_size" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>
					    <div header="推荐理由" field="recommended_reason" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>
					     <div header="赠品说明" field="gift_note" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>
					
					 
					  
				</div>
			  </div>
				




	<script type="text/javascript">
		mini.parse();
		
	
		var pid = mini.get('pid').getValue();
		mini.get('combo1').setValue(pid);
		change();
		function onFilterChanged(e) {
			var namebox = mini.get("name");
			var codebox = mini.get("code");
			var name = namebox.getValue().toLowerCase();
			var code = codebox.getValue().toLowerCase();
			//多条件组合过滤
			grid1.filter(function(row) {

				//name
				var r1 = true;
				if (namebox) {
					r1 = String(row.name).toLowerCase().indexOf(name) != -1;
				}

				var r2 = true;
				if (code) {
					r2 = String(row.code).toLowerCase().indexOf(code) != -1;
				}

				return r1 && r2;
			});
		}

		var grid2 = mini.get("grid2");
		
		
		 grid2.on("drawcell", function (e) {
	            var record = e.record,
	                column = e.column,
	                field = e.field,
	                value = e.value;
	            	if (field == "maoli") {
	            		 var zzs = (fmt(record.mall_price)-fmt(record.purchase_price))*0.07; //增值
	            		 e.cellHtml=(fmt(record.mall_price)-fmt(record.purchase_price)+fmt(record.rebate)-fmt(record.freight)-fmt(record.gift_price)-fmt(record.bank_commission)-zzs).toFixed(2);
	          		  }
	            	
	            	if (field == "maolilv") {
	            		 var zzs = (fmt(record.mall_price)-fmt(record.purchase_price))*0.07; //增值
	            		 var  maoli =(fmt(record.mall_price)-fmt(record.purchase_price)+fmt(record.rebate)-fmt(record.freight)-fmt(record.gift_price)-fmt(record.bank_commission)-zzs);
	            	
	            		e.cellHtml= (maoli/fmt(record.mall_price)*100).toFixed(2);
	            		
	          		  }
	            	
	            	if (field == "zzs") {
	            		 var zzs = (fmt(record.mall_price)-fmt(record.purchase_price))*0.07; //增值
	            		e.cellHtml= (zzs).toFixed(2);
	            		
	          		  }
	            	
	            	if (field == "img") {
	            		
	            		 e.cellHtml="<img src='"+record.img+"' class='item-img'>";
	          		  }

	            });
		
		 function fmt(num){
			 return parseFloat(num);
		 }
		 
		function cellendedit(e){
			 column = e.column,
		        field = e.field,
		        value = e.value;
				if(e.record._state!=null)
				update(mini.encode(e.record));
		}
		
		
		
		function update(data){
			
			$.ajax({
				url : "/Shelves/upadteDetailed",
				type : "post",
				data : {
					data : data
				},
				dataType : 'json',
				success : function(data) {
					change();
				}
			});
		}
	

		function search() {
			var key = mini.get('key').getValue();
			grid1.load({
				'key' : key
			});
		}
		function adds() {

			var id = mini.get('combo1').getValue();
			if (id == '') {
				mini.alert('请选择清单');
				return;
			}
			var data = new Object();
			var items = grid1.getSelecteds();
			grid1.removeRows(items);
			var selecteds = grid2.getData();
			var check = true;
			var dataIndex = 0;
			for (var index = 0; index < items.length; index++) {
				for (var sindex = 0; sindex < selecteds.length; sindex++) {
					if (items[index].code == selecteds[sindex].code) {
						check = false;
					}
				}
				if (check) {
					grid2.addRow(items[index]);
					data[dataIndex] = items[index];
					dataIndex++;
				} else {
					check = true;
				}
			}
			if (data.length == 0)
				return;
			var postData = mini.encode(data);
			$.ajax({
				url : "/Shelves/saveShelvesDetailed",
				type : "post",
				data : {
					data : postData,
					pid : id
				},
				dataType : 'json',
				success : function(data) {
					change();
				}
			});

		}
		function addAll() {
			var items = grid1.getData();
			grid1.removeRows(items);
			grid2.addRows(items);
		}

		function removes() {
			var items = grid2.getSelecteds();
			var ids = '';
			for (var index = 0; index < items.length; index++) {
				ids += items[index].id + ",";
			}

			$.ajax({
				url : "/Shelves/delShelvesDetailed",
				type : "post",
				data : {
					ids : ids
				},
				dataType : 'json',
				success : function(data) {
				}
			});
			grid2.removeRows(items);
			//  grid1.addRows(items);
		}

		function change() {

			var id = mini.get('combo1').getValue();
			if (id == '') {

				return;
			}
			loadingmsg('加载清单明细..')

			$.ajax({
				url : "/Shelves/getShelvesDetailed",
				type : "post",
				data : {
					pid : id
				},
				dataType : 'json',
				success : function(data) {
					colseloading();
					grid2.setData(data);
					$('#qdan-show').show();
				}
			});

		}

		function promptClick() {

			mini.prompt("请输入清单名称：", "请输入", function(action, value) {
				if (action == "ok") {
					if (value == '') {
						mini.alert('名称不能为空');
						return;
					}
					saveshelvesList(value);
				}

			});
		}

		function saveshelvesList(name) {

			$.ajax({
				url : "/Shelves/saveshelvesList",
				type : "post",
				data : {
					name : name
				},
				dataType : 'json',
				success : function(data) {
					if (data.code != 0) {
						mini.alert('添加成功');
						mini.get('combo1').setData(data.data);
						mini.get('combo1').setValue(data.code);
					}

				}
			});

		}

		function onButtonEdit(e) {
			var btnEdit = this;
			var id = mini.get('combo1').getValue();
			if (id == '') {
				mini.alert('请选择清单');
				return;
			}
			if (grid2.getData().length == 0) {
				mini.alert('清单物料数据为空');
				return;
			}
			mini.open({
				url : "/Shelves/select",
				title : "选择平台",
				width : 650,
				height : 380,
				ondestroy : function(action) {

					if (action == "ok") {
						var iframe = this.getIFrameEl();
						var data = iframe.contentWindow.GetData();
						data = mini.clone(data);
						data.listId = mini.get('combo1').getValue();
						send(data);

					}
				}
			});

		}
		  jQuery('.item-img').live('click',function(){
	        	window.open(jQuery(this).attr('src'));
	        })
		 
        function send(){
        	var id = mini.get('combo1').getValue();
        	if(id==''){
        	mini.alert('请选择清单');
        	return;
        	}
        	loadingmsg('发送中....');
            $.ajax({
                url: "/Shelves/sendnotice",
                type: "post",
                data: { id:id },
                dataType:'json',
                success: function (data) {
                	  mini.unmask(document.body);
                   	  mini.alert(data.msg)
               	
                   
                }
            });
        }
		  
		  
		  jQuery('table img').live('hover',function(event){
			  
			  if(event.type=='mouseenter'){ 
				  jQuery(".show-pic img").attr('src',jQuery(this).attr('src'))
				  jQuery('.show-pic').css({'left':event.pageX+'px','top':'30%'})
				  jQuery(".show-pic").fadeIn(500);
				  }else{ 
						jQuery(".show-pic").hide();
				  }
			}
		  )

	</script>
	
</body>

				</div>
			</div>
		</div>
		<iframe src="<?php echo U('push/client');?>" class="push" id="push"></iframe>
		<!-- Mainly scripts -->
		<script src="/Public/Ins/js/jquery-2.1.1.js"></script>
		<script src="/Public/Ins/js/bootstrap.min.js"></script>
		<script src="/Public/Ins/js/plugins/metisMenu/jquery.metisMenu.js"></script>
		<script src="/Public/Ins/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		

		<!-- Custom and plugin javascript -->
		<script src="/Public/Ins/js/inspinia.js"></script>
		<script src="/Public/Ins/js/common.js"></script>
		<script src="/Public/Ins/js/plugins/pace/pace.min.js"></script>
		<?php if(!empty($plugin["jquery-ui"])): ?><script src="/Public/Ins/js/plugins/jquery-ui/jquery-ui.min.js"></script>
	<script src="/Public/Ins/js/plugins/nouslider/jquery.nouislider.min.js"></script><?php endif; ?>

	<script src="/Public/Ins/js/plugins/date-time/moment-with-locales.js"></script>
	<script src="/Public/Ins/js/plugins/date-time/bootstrap-datetimepicker.js"></script>


<?php if(!empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script>
	<?php if(empty($plugin["auth"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.setting.js"></script><?php endif; endif; ?>

<?php if(!empty($plugin["editor"])): if(empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script><?php endif; ?>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.min.js"></script>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.setting.js"></script><?php endif; ?>

<?php if(!empty($plugin["baidu_map"])): ?><script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=EE6745c36d96321e90b7015f3de4a4ee"></script><?php endif; ?>

<script src="/Public/Ins/js/plugins/toastr/toastr.min.js"></script>
<script src="/Public/Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
<script src="/Public/Ins/js/plugins/bootbox/bootbox.min.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
		<?php if(!empty($plugin["date"])): ?>$('.input-date').datetimepicker({
			format : 'YYYY-MM-DD',
			locale : 'zh-cn',
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});
		
		$(".input-daterange input").datetimepicker({
			format : "YYYY-MM-DD",
			locale : 'zh-cn',
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});

		$("#start_date").on("dp.change", function(e) {
			if ($("#end_date").length > 0) {
				$('#end_date').data("DateTimePicker").minDate(e.date);
			}
		});
		
		$("#end_date").on("dp.change", function(e) {
			if ($("#start_date").length > 0) {
				$('#start_date').data("DateTimePicker").maxDate(e.date);
			}
		});

		$(".input-date-time").datetimepicker({
			format : 'YYYY-MM-DD HH:mm',
			locale : 'zh-cn',
			sideBySide : true,
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});<?php endif; ?>		 
	}); 
</script>
		 <script type="text/javascript">
	function save() {
		if ($("input:checked[name='user_id[]']").length < 1) {
			ui_error("请选择用户");
			return false;
		}
		;

		var vars = $("#form_data").serialize();
		sendAjax("<?php echo U('save_user');?>", vars, function(data) {
			if (data.status) {
				ui_alert(data.info, function() {
					parent.location.reload(true);
					myclose();
				});
			}
		});

	}
</script> 
	</body>
</html>